package com.itheima.tanhua.dubbo.api;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.tanhua.api.ProblemsApi;
import com.itheima.tanhua.domain.Problems;
import com.itheima.tanhua.dubbo.mappers.ProblemsMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lff
 * @date 2022/4/8
 */
@DubboService
public class ProblemsApiImpl implements ProblemsApi {
    @Autowired
    private ProblemsMapper problemsMapper;

    @Override
    public Map<Long, List<Problems>> findProblemsToMap(List<Long> questionIds, List<String> problemIds) {
        Map<Long, List<Problems>> results = new HashMap<>();
        for (int i = 0; i < questionIds.size(); i++) {
            //获取problemId
            Long[] ids = JSON.parseObject(problemIds.get(i), Long[].class);
            LambdaQueryWrapper<Problems> qw = Wrappers.lambdaQuery(Problems.class);
            qw.in(Problems::getId, ids);
            //查询
            List<Problems> problemsList = problemsMapper.selectList(qw);
            results.put(questionIds.get(i), problemsList);
        }
        return results;
    }
}
